Fixed tests
authorKalita Alexey <kalita.alexey@outlook.com>
Thu, 19 Jan 2017 20:43:56 +0000 (23:43 +0300)
committerKalita Alexey <kalita.alexey@outlook.com>
Thu, 19 Jan 2017 20:43:56 +0000 (23:43 +0300)
tests/build.rs
tests/cargotest/support/mod.rs

index c62513ebd9b6c2015ffd3c8f565fe4a817d3ee5a..af1ad23e0159e04881e4af5e16286517a68c61c6 100644 (file)
@@ -1906,7 +1906,8 @@ fn example_as_lib() {
         .file("src/lib.rs", "")
         .file("examples/ex.rs", "");
 
-    assert_that(p.cargo_process("build"), execs().with_status(0));
+    assert_that(p.cargo_process("build").arg("--example=ex"), execs().with_status(0));
+    assert_that(&p.example_lib("ex", "lib"), existing_file());
 }
 
 #[test]
@@ -1923,9 +1924,10 @@ fn example_as_rlib() {
             crate-type = ["rlib"]
         "#)
         .file("src/lib.rs", "")
-        .file("examples/ex.rs", "");
+        .file("examples/ex.rs", "fn a() {}");
 
-    assert_that(p.cargo_process("build"), execs().with_status(0));
+    assert_that(p.cargo_process("build").arg("--example=ex"), execs().with_status(0));
+    assert_that(&p.example_lib("ex", "rlib"), existing_file());
 }
 
 #[test]
@@ -1944,7 +1946,8 @@ fn example_as_dylib() {
         .file("src/lib.rs", "")
         .file("examples/ex.rs", "");
 
-    assert_that(p.cargo_process("build"), execs().with_status(0));
+    assert_that(p.cargo_process("build").arg("--example=ex"), execs().with_status(0));
+    assert_that(&p.example_lib("ex", "dylib"), existing_file());
 }
 
 #[test]
@@ -1963,7 +1966,8 @@ fn example_as_proc_macro() {
         .file("src/lib.rs", "")
         .file("examples/ex.rs", "");
 
-    assert_that(p.cargo_process("build"), execs().with_status(0));
+    assert_that(p.cargo_process("build").arg("--example=ex"), execs().with_status(0));
+    assert_that(&p.example_lib("ex", "proc-macro"), existing_file());
 }
 
 #[test]
index 3be2097190eb6a7d88770c917e892c8c0165f587..de218b6fcc44d690da5afec6670b256914f88e6f 100644 (file)
@@ -114,6 +114,25 @@ impl ProjectBuilder {
 
     pub fn url(&self) -> Url { path2url(self.root()) }
 
+    pub fn target_debug_dir(&self) -> PathBuf {
+        self.build_dir().join("debug")
+    }
+
+    pub fn example_lib(&self, name: &str, kind: &str) -> PathBuf {
+        let prefix = ProjectBuilder::get_lib_prefix(kind);
+
+        let extension = ProjectBuilder::get_lib_extension(kind);
+
+        let lib_file_name = format!("{}{}.{}",
+                                    prefix,
+                                    name,
+                                    extension);
+
+        self.target_debug_dir()
+            .join("examples")
+            .join(&lib_file_name)
+    }
+
     pub fn bin(&self, b: &str) -> PathBuf {
         self.build_dir().join("debug").join(&format!("{}{}", b,
                                                      env::consts::EXE_SUFFIX))
@@ -188,6 +207,43 @@ impl ProjectBuilder {
         buffer
     }
 
+    fn get_lib_prefix(kind: &str) -> &str {
+        match kind {
+            "lib" | "rlib" => "lib",
+            "staticlib" | "dylib" | "proc-macro" => {
+                if cfg!(windows) {
+                    ""
+                } else {
+                    "lib"
+                }
+            }
+            _ => unreachable!()
+        }
+    }
+
+    fn get_lib_extension(kind: &str) -> &str {
+        match kind {
+            "lib" | "rlib" => "rlib",
+            "staticlib" => {
+                if cfg!(windows) {
+                    "lib"
+                } else {
+                    "a"
+                }
+            }
+            "dylib" | "proc-macro" => {
+                if cfg!(windows) {
+                    "dll"
+                } else if cfg!(target_os="macos") {
+                    "dylib"
+                } else {
+                    "so"
+                }
+            }
+            _ => unreachable!()
+        }
+    }
+
     fn rm_root(&self) {
         self.root.rm_rf()
     }